<?php
/**
 * @Notes:【】
 * @Date: 2022-06-17 0:50
 */

namespace App\Listener;

use Hyperf\DbConnection\Db;
use Hyperf\Event\Contract\ListenerInterface;

use Hyperf\Database\Events\QueryExecuted;
use Hyperf\Event\Annotation\Listener;

use Hyperf\Framework\Event\BeforeWorkerStart;
use Hyperf\Logger\LoggerFactory;
use Hyperf\Server\ServerFactory;
use Hyperf\Server\ServerManager;
use Hyperf\Utils\Arr;
use Hyperf\Utils\Str;
use Jaeger\Cache;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;

/**
 * @Listener
 */
class BeforeWorkerStartListener implements ListenerInterface
{
    /**
     * @var LoggerInterface
     */
    private $logger;


    public function __construct(ContainerInterface $container)
    {
        $this->logger = $container->get(LoggerFactory::class)->get('sql');
    }

    public function listen(): array
    {
        return [
            BeforeWorkerStart::class,
        ];
    }

    /**
     * @param QueryExecuted $event
     */
    public function process(object $event)
    {
        /** @var \Swoole\WebSocket\Server $server */
        $server = $event->server;
        Db::enableQueryLog();
//        $port = _Collect(config('server.servers'))->where('name', 'ws')
//                ->first()['port'] ?? 0;
        _Cache()->set('SERVER_RUN_ID', SERVER_RUN_ID);

//        dump(ServerManager::list());

//        dump($server);

//        $server = di()->get(ServerFactory::class)->getServer()->getServer();
//        dump($server);
    }
}